<%@ page contentType="text/html; charset=UTF-8"%>
<script src="layer/js/jquery.js" type="text/javascript"></script>
<script src="layer/js/PopupDiv_v1.0.js" type="text/javascript"></script>
<script src="layer/js/demo.js" type="text/javascript"></script>
<link rel="stylesheet" href="layer/css/demo.css" type="text/css" >
<table border="0" style="border-collapse: collapse; width: 100%;margin-top: 20px;border: 1px solid #e4e4e4;">
	<tr >
		<td >SensorHub Server列表:</td>	
		<td ></td>
		<td style="text-align:right;"><button id="PopupDivBtn_35" type="button">添加</button></td>  
	</tr>

</table>
<table id="sensorHubTable" border="1" style="border-collapse: collapse; width: 100%; text-align: center;border: 1px solid #e4e4e4;"></table>
  
<div id="PopupDiv_35" style="display:none" align="center"><br/>
	<table style="border: 1px solid #e4e4e4;">
		<tr>
			<td>SensorHub Server IP:</td>
			<td><input id="serverIp" type="text" value="" /></td>
		</tr>
		<tr>
			<td>SensorHub Server Port:</td>
			<td><input id="serverPort" type="text" value="" /></td>
		</tr>				
		<tr>
			<td></td>
			<td style="text-align: right;"><button id="save" onclick="addSensorHub()">确定</button></td>
		</tr>
	</table>
</div>  	



<script type="text/javascript">
	getSensorHub();
	
  function getSensorHub(){
		$.post("sensorHubAction", {
			"actionType" : "getSensorHub"
		}, function(data) {
			if(undefined==data.er){
				if(data.length!=0){
					var html = "";
					for(var i =0 ; i <data.length;i++){
						var obj = data[i];
						html += "<tr ><td >"+obj.hostIp+"</td ><td > "+obj.port+"</td><td><button onclick='deleteSensorHub("+ obj.id +")'>删除</button></td></tr>";
					}
					insertSensorHubTable(html);
				}else{
					insertSensorHubTable("<tr ><td COLSPAN='3'></td></tr>");	
				}
			}else{
				insertSensorHubTable("<tr ><td COLSPAN='3'> "+data.er+"</td></tr>");
			}
		},"json");
  }
  
  function insertSensorHubTable(val){
  	var html = "<tr><th>SensorHub Server IP</th><th> SensorHub Server Port</th><th>操作</th></tr>	";
		html+=val;
  	$("#sensorHubTable").html(html);
  }
  
  function deleteSensorHub(val){
	  $.post("sensorHubAction", {
			"actionType" : "deleteSensorHub",
			"id" : val
		}, function(data) {
			
		}, "json");	
	  getSensorHub();
  }
  
  function addSensorHub(){
	  $.post("sensorHubAction", {
			"actionType" : "addSensorHub",
			"serverIp" : $("#serverIp").val(),
			"serverPort" :  $("#serverPort").val()
		}, function(data) {
		}, "json");
	  getSensorHub();
  }
  
</script>